1 // Equipo Poncho, Carriel y Ruana
22 template <class T
> string
toStr(const T
&x
)
23 { stringstream s
; s
<< x
; return s
.str(); }
24 template <class T
> int toInt(const T
&x
)
25 { stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
27 #define For(i, a, b) for (int i=(a); i<(b); ++i)
28 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
29 #define D(x) cout << #x " = " << (x) << endl;
31 const double EPS
= 1e-9;
33 int cmp(double x
, double y
= 0, double tol
= EPS
) {
34 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
44 vector
<int> gg1
[MAXN
], gg2
[MAXN
];
47 void bfs(int start
, vector
<int> g
[MAXN
]) {
48 For(i
, 0, n
) dist
[i
] = oo
;
56 for (int k
= 0; k
< g
[u
].size(); ++k
) {
59 if (dist
[v
] < oo
) continue;
60 dist
[v
] = dist
[u
] + 1;
66 bool equal(long long a
, long long b
) {
69 if (g2
[i
][j
] >= oo
) return false;
70 long long now
= g2
[i
][j
];
71 long long cota
= g1
[i
][j
] * a
+ b
;
73 //printf("From %d to %d: now = %d, cota = %d, old = %d\n", i, j, (int)now, (int)cota, g1[i][j]);
84 string s
; getline(cin
, s
);
86 For (i
, 0, n
) For(j
, 0, n
) g1
[i
][j
] = g2
[i
][j
] = oo
;
87 For (i
, 0, n
) gg1
[i
].clear(), gg2
[i
].clear();
89 for (int i
= 0; i
< n
; ++i
) {
92 int first
; sin
>> first
; first
--;
94 while (sin
>> other
) {
97 gg1
[first
].push_back(other
);
101 for (int i
= 0; i
< n
; ++i
) {
104 int first
; sin
>> first
; first
--;
106 while (sin
>> other
) {
108 g2
[first
][other
] = 1;
109 gg2
[first
].push_back(other
);
112 For(i
, 0, n
) g1
[i
][i
] = g2
[i
][i
] = 0;
116 if (a
== 0 and b
== 0 and n
> 1) {
121 //puts("G1"); For(i, 0, n){ For(j, 0, n) { printf("%10d", g1[i][j]); } puts(""); } puts("");
122 //puts("G2"); For(i, 0, n){ For(j, 0, n) { printf("%10d", g2[i][j]); } puts(""); } puts("");